package com.xzq.bugstack;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @Author xzq
 * @Description //TODO
 * @Date 2021/11/19 14:03
 * @Version 1.0.0
 **/
public class NettyClient {
    public static void main(String[] args) {
        new NettyClient().connecte(9999);
    }

    private void connecte(int i) {
        NioEventLoopGroup workerGroup = new NioEventLoopGroup();
        try {
            new Bootstrap()
                    .group(workerGroup)
                    .channel(NioSocketChannel.class)
                    .option(ChannelOption.AUTO_READ, true)
                    .handler(new MyChannelIntializer())
                    .connect("127.0.0.1", i)
                    .sync()
                    .channel()
                    .closeFuture()
                    .sync();
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            workerGroup.shutdownGracefully();
        }
    }
}
